﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Logging;
using System.Globalization;
using Tanmia.Basis;
using Tanmia.Basis.ViewInterface;
using Tanmia.Basis.Security;

namespace SaryaAccounting
{
    /// <summary>
    /// Interaction logic for LoginView.xaml
    /// </summary>
    public partial class LoginView : Window, IUserSelector
    {
        private IAuthenticationService authSrv;
        private ILoggerFacade logger;
        private int loginTryCounter;
        private ApplicationUserInfo userInfo;

        public LoginView(IAuthenticationService authSrv, ILoggerFacade logger)
        {
            InitializeComponent();

            this.authSrv = authSrv;
            this.logger = logger;

            userInfo = new ApplicationUserInfo();
            DataContext = userInfo;
        }

        #region IUserSelector Members

        public ApplicationUserInfo SelectUser()
        {
            ShowDialog();

            return userInfo;
        }

        #endregion

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            //if (!string.IsNullOrEmpty(txtUsername.Text) && !string.IsNullOrEmpty(txtPassword.Text))
            //    if (loginTryCounter < 3)
            //        if (!authSrv.Authenticate(userInfo.Username, userInfo.Password))
            //        {
            //            logger.Log(string.Format(CultureInfo.CurrentCulture, SaryaAccounting.Properties.Resources.AuthenticationFailed, userInfo.Username, userInfo.Password), Category.Debug, Priority.Low);
            //            MessageBox.Show(string.Format("اسم المستخدم أو كلمة المرور غير صحيحة. \r\nالمحاولة رقم: {0}.", loginTryCounter + 1));
            //            loginTryCounter++;
            //        }
            //        else
            //        {
            //            logger.Log(string.Format(CultureInfo.CurrentCulture, SaryaAccounting.Properties.Resources.AuthenticationSuccessed, userInfo.Username), Category.Debug, Priority.Low);
            //            Close();
            //            return;
            //        }
            //    else
            //        Environment.Exit(1);
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            Environment.Exit(1);
        }

    }
}
